package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class JFrame_main extends JFrame {
    // 使用SpringLayout布局管理器
    private SpringLayout springLayout = new SpringLayout();
    // 中间面板和顶部面板
    private JPanel centerPanel = new JPanel(springLayout);
    private JPanel northPanel = new JPanel();
    // 创建标签
    private JLabel label1 = new JLabel("CloudSim", JLabel.CENTER);
    private JLabel label2 = new JLabel("进入 CloudSim 样例");
    private JLabel label3 = new JLabel("进入 CloudSim 实例");
    private JLabel label4 = new JLabel("信管创新班22-1 2022215030 朱建宇");

    public JFrame_main() {
        super();
        Container container = getContentPane();

        // 设置标签字体
        label1.setFont(new Font("微软雅黑", Font.BOLD, 60));
        label2.setFont(new Font("微软雅黑", Font.BOLD, 30));
        label3.setFont(new Font("微软雅黑", Font.BOLD, 30));
        label4.setFont(new Font("微软雅黑", Font.BOLD, 15));

        // 设置标签文字颜色
        label1.setForeground(new Color(0, 0, 0));
        label2.setForeground(new Color(0, 0, 0));
        label3.setForeground(new Color(0, 0, 0));
        label4.setForeground(Color.DARK_GRAY);

        // 设置面板的背景色
        northPanel.setBackground(new Color(240, 240, 240));
        centerPanel.setBackground(new Color(255, 255, 255));

        // 将标签添加到面板
        northPanel.add(label1);
        centerPanel.add(label2);
        centerPanel.add(label3);
        centerPanel.add(label4);

        // 使用SpringLayout管理标签的位置
        springLayout.putConstraint(SpringLayout.NORTH, label1, 50, SpringLayout.NORTH, northPanel);
        springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, label1, 0, SpringLayout.HORIZONTAL_CENTER, centerPanel);

        springLayout.putConstraint(SpringLayout.NORTH, label2, 50, SpringLayout.NORTH, centerPanel);
        springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, label2, 0, SpringLayout.HORIZONTAL_CENTER, centerPanel);

        springLayout.putConstraint(SpringLayout.NORTH, label3, 50, SpringLayout.SOUTH, label2);
        springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, label3, 0, SpringLayout.HORIZONTAL_CENTER, centerPanel);

        springLayout.putConstraint(SpringLayout.NORTH, label4, 50, SpringLayout.SOUTH, label3);
        springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, label4, 0, SpringLayout.HORIZONTAL_CENTER, centerPanel);

        // 添加面板到窗口的不同区域
        container.add(northPanel, BorderLayout.NORTH);
        container.add(centerPanel, BorderLayout.CENTER);

        // 为标签2添加鼠标监听器
        label2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // 点击标签2时，打开Example_JFrame窗口
                new Example_JFrame();
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // 鼠标悬停时改变标签文字颜色
                label2.setForeground(new Color(40, 43, 47, 116));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // 鼠标移出时恢复原来的文字颜色
                label2.setForeground(new Color(0, 0, 0));
            }
        });

        // 为标签3添加鼠标监听器
        label3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // 点击标签3时，打开DIY_JFrame窗口
                new DIY_JFrame();
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // 鼠标悬停时改变标签文字颜色
                label3.setForeground(new Color(40, 43, 47, 116));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // 鼠标移出时恢复原来的文字颜色
                label3.setForeground(new Color(0, 0, 0));
            }
        });

        // 设置窗口大小和位置
        setSize(700, 450);
        setLocationRelativeTo(null); // 窗口居中显示
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 关闭窗口时退出程序
        setVisible(true); // 设置窗口可见
    }

    // 主函数，启动程序
    public static void main(String[] args) {
        new JFrame_main(); // 创建并显示JFrame_main窗口
    }
}
